package cn.tiancaifan.micro.controller.system;


import cn.tiancaifan.micro.entity.SystemResults;
import cn.tiancaifan.micro.service.DataBaseService;
import com.aliyun.oss.model.OSSObjectSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/system/data")
public class DataBaseController {

    @Autowired
    DataBaseService dataBaseService;

    @GetMapping("/")
    public SystemResults backUp(){
        return dataBaseService.backUp();
    }

    @GetMapping("/initSystem")
    public SystemResults initSystem(String password){
        return dataBaseService.initSystem(password);
    }

    @PostMapping("/")
    public SystemResults recovery(MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();
        return dataBaseService.recovery(inputStream);
    }

    @GetMapping("/list")
    public SystemResults getListSql(){
        return dataBaseService.getListSql();
    }

    @PostMapping("/delete")
    public SystemResults deleteSql(@RequestBody OSSObjectSummary ossObjectSummary){
        return dataBaseService.deleteSql(ossObjectSummary);
    }
    @PostMapping("/recovery")
    public SystemResults recoverySql(@RequestBody OSSObjectSummary ossObjectSummary){
        return dataBaseService.recoverySql(ossObjectSummary);
    }
}
